package org.example.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.seata.spring.annotation.GlobalTransactional;
import jakarta.annotation.Resource;
import org.example.bean.Order;
import org.example.feign.StokeFeign;
import org.example.mapper.OrderMapper;
import org.example.service.OrderService;
import org.springframework.stereotype.Service;

/**
 * @Auther:Liu
 * @Testname:OrderServiceImpl
 * @Date:2025/9/25 15:20
 */
@Service
public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements OrderService {
    @Resource
    private StokeFeign stokeFeign;

    @GlobalTransactional
    public int createOrder(Order order) {
        //1.创建订单
        boolean b = save(order);
        //2.修改库存
        stokeFeign.updateStoke(order.getGid(), order.getNumber());
        return b ? 1 : 0;
    }
}
